import Qt 4.7
import "scripts.js" as Game

Rectangle {

    id : gameArea
    width: 360
    height: 630

    property int score: 0
    property int lives: 3
    property int clickCount : 0
    property int hideTimerInterval: 1500
    property int gameTimerInterval: 1000

    StartScreen {
        id : mainView
        height: parent.height
        width:  parent.width
        visible : true
    }

    GameScreen {
        id : gameView
        height: parent.height
        width:  parent.width
        x : parent.width
        scoreText: score
        livesText: lives
        visible: false
    }

    InfoScreen {
        id: infoView
        height: parent.height
        width:  parent.width
        x : parent.width
        visible : false
    }

    HighScoreScreen {
        id: highScoreView
        height: parent.height
        width:  parent.width
        x : parent.width
        visible : false
    }

    Timer {
         id: gameTimer
         interval: gameTimerInterval
         running: false
         repeat: true
         onTriggered: Game.gameLoop(true)
     }

    Timer {
             id: hideTimer1
             interval: 1500
             running: false
             repeat: false
             onTriggered: Game.hideMonkey(1)
         }
    Timer {
             id: hideTimer2
             interval: 1500
             running: false
             repeat: false
             onTriggered: Game.hideMonkey(2)
         }
    Timer {
             id: hideTimer3
             interval: 1500
             running: false
             repeat: false
             onTriggered: Game.hideMonkey(3)
         }
    Timer {
             id: hideTimer4
             interval: 1500
             running: false
             repeat: false
             onTriggered: Game.hideMonkey(4)
         }
    Timer {
             id: hideTimer5
             interval: 1500
             running: false
             repeat: false
             onTriggered: Game.hideMonkey(5)
         }
    Timer {
             id: hideTimer6
             interval: 1500
             running: false
             repeat: false
             onTriggered: Game.hideMonkey(6)
         }
    Timer {
             id: hideTimer7
             interval: 1500
             running: false
             repeat: false
             onTriggered: Game.hideMonkey(7)
         }
    Timer {
             id: hideTimer8
             interval: 1500
             running: false
             repeat: false
             onTriggered: Game.hideMonkey(8)
         }

         Image {
             id: image2

             width: 40
             height: 40
             anchors.right: parent.right
             anchors.rightMargin: 5
             anchors.top: parent.top
             anchors.topMargin: 5
             fillMode: Image.PreserveAspectFit
             opacity: 0.4

             source: "images/close.png"
             MouseArea {
                 anchors.fill: parent
                 onClicked: {

                     appData.close();
                 }
             }
         }

         states: [
             State {
                 name: "game"

            PropertyChanges {
                target: mainView
                x: - ( gameArea.width )
                height: gameArea.height

            }

            PropertyChanges {
                target: gameView
                x: 0
                height: gameArea.height

            }

        },
        State {
            name: "info"

            PropertyChanges {
                target: mainView
                x: - ( gameArea.width )
                height: gameArea.height

            }

            PropertyChanges {
                target: infoView
                x: 0
                height: gameArea.height

            }
        },
        State {
            name: "highscore"
            PropertyChanges {
                target: gameView
                x: - ( gameArea.width )
                height: gameArea.height

            }

            PropertyChanges {
                target: mainView
                x: - ( gameArea.width )
                height: gameArea.height
            }

            PropertyChanges {
                target: highScoreView
                x: 0
                height: gameArea.height
            }
        }
    ]

    transitions: [

        Transition {
            from: "game"
            to: "highscore"
            SequentialAnimation {
                ScriptAction {
                    script: {
                      highScoreView.visible = true;
                      highScoreView.state = ""
                    }
                }
                NumberAnimation { properties: "x";  duration: 300; easing.type: "OutInSine"}
                ScriptAction {
                    script: {
                      gameView.visible = false;
                    }
                }
            }
        },

        Transition {
            from: "highscore"
            to: ""
            SequentialAnimation {
                ScriptAction {
                    script: {
                      mainView.visible = true
                    }
                }
                NumberAnimation { properties: "x";  duration: 300; easing.type: "OutInSine"}
                ScriptAction {
                    script: {
                      highScoreView.visible = false;
                    }
                }
            }
        },
        Transition {
            from: ""
            to: "game"
            SequentialAnimation {
                ScriptAction {
                    script: {

                      gameView.visible = true;
                    }
                }
                NumberAnimation { properties: "x";  duration: 300; easing.type: "OutInSine"}
                ScriptAction {
                    script: {
                      mainView.visible = false;
                    }
                }
            }
        },
        Transition {
            from: "game"
            to: ""
            SequentialAnimation {
                ScriptAction {
                    script: {
                      mainView.visible = true;
                    }
                }
                NumberAnimation { properties: "x";  duration: 300; easing.type: "OutInSine"}
                ScriptAction {
                    script: {
                      gameView.visible = false;
                    }
                }
            }
        },

        Transition {
            from: ""
            to: "info"
            SequentialAnimation {
                ScriptAction {
                    script: {
                      infoView.visible = true;
                    }
                }
                NumberAnimation { properties: "x";  duration: 300; easing.type: "OutInSine"}
                ScriptAction {
                    script: {
                      mainView.visible = false;
                    }
                }
            }
        },

        Transition {
            from: "info"
            to: ""
            SequentialAnimation {
                ScriptAction {
                    script: {
                      mainView.visible = true;
                    }
                }
                NumberAnimation { properties: "x";  duration: 300; easing.type: "OutInSine"}
                ScriptAction {
                    script: {
                      infoView.visible = false;
                    }
                }
            }
        },

        Transition {
            from: ""
            to: "highscore"
            SequentialAnimation {
                ScriptAction {
                    script: {
                      highScoreView.visible = true;
                      highScoreView.state = ""
                    }
                }
                NumberAnimation { properties: "x";  duration: 300; easing.type: "OutInSine"}
                ScriptAction {
                    script: {
                      mainView.visible = false;
                    }
                }
            }
        }
    ]

}
